<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
  <meta name="description" content="API docs for the sendMessageForNew method from the V2TIMMessageManager class, for the Dart programming language.">
  <title>sendMessageForNew method - V2TIMMessageManager class - v2_tim_message_manager library - Dart API</title>


  
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" rel="stylesheet">
  
  <link rel="stylesheet" href="../../static-assets/github.css?v1">
  <link rel="stylesheet" href="../../static-assets/styles.css?v1">
  <link rel="icon" href="../../static-assets/favicon.png?v1">

  
</head>


<body data-base-href="../../" data-using-base-href="false" class="light-theme">

<div id="overlay-under-drawer"></div>

<header id="title">
  <span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="../../index.html">tencent_cloud_chat_sdk</a></li>
    <li><a href="../../web_manager_v2_tim_message_manager/web_manager_v2_tim_message_manager-library.html">web&#47;manager&#47;v2_tim_message_manager.dart</a></li>
    <li><a href="../../web_manager_v2_tim_message_manager/V2TIMMessageManager-class.html">V2TIMMessageManager</a></li>
    <li class="self-crumb">sendMessageForNew&lt;<wbr><span class="type-parameter">T</span>, <span class="type-parameter">F</span>&gt; method</li>
  </ol>
  <div class="self-name">sendMessageForNew</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
  <div class="toggle" id="theme-button" title="Toggle brightness">
    <label for="theme">
      <input type="checkbox" id="theme" value="light-theme">
      <span id="dark-theme-button" class="material-symbols-outlined">
        dark_mode
      </span>
      <span id="light-theme-button" class="material-symbols-outlined">
        light_mode
      </span>
    </label>
  </div>
</header>
<main>

<div
    id="dartdoc-main-content"
    class="main-content"
    data-above-sidebar="web_manager_v2_tim_message_manager&#47;V2TIMMessageManager-class-sidebar.html"
    data-below-sidebar="">
    <div>
<h1><span class="kind-method">sendMessageForNew&lt;<wbr><span class="type-parameter">T</span>, <span class="type-parameter">F</span>&gt;</span> method 
</h1></div>

    <section class="multi-line-signature">
      

<span class="returntype"><a href="https://api.flutter.dev/flutter/dart-async/Future-class.html">Future</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../../web_compatible_models_v2_tim_value_callback/V2TimValueCallback-class.html">V2TimValueCallback</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="../../web_compatible_models_v2_tim_message/V2TimMessage-class.html">V2TimMessage</a></span>&gt;</span></span>&gt;</span></span>
<span class="name ">sendMessageForNew</span>&lt;<wbr><span class="type-parameter">T</span>, <span class="type-parameter">F</span>&gt;(<wbr><ol class="parameter-list"><li><span class="parameter" id="sendMessageForNew-param-params">{<span>required</span> <span class="type-annotation"><a href="https://api.flutter.dev/flutter/dart-core/Map-class.html">Map</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="https://api.flutter.dev/flutter/dart-core/String-class.html">String</a></span>, <span class="type-parameter">dynamic</span>&gt;</span></span> <span class="parameter-name">params</span>}</span></li>
</ol>)

      

    </section>
    


    
<section class="summary source-code" id="source">
  <h2><span>Implementation</span></h2>
  <pre class="language-dart"><code class="language-dart">Future&lt;V2TimValueCallback&lt;V2TimMessage&gt;&gt; sendMessageForNew&lt;T, F&gt;({required Map&lt;String, dynamic&gt; params}) async {
  String? id = params[&#39;id&#39;];
  var messageElem;
  try {
    final groupID = params[&#39;groupID&#39;] ?? &#39;&#39;;
    final recveiver = params[&#39;receiver&#39;] ?? &#39;&#39;;
    final haveTwoValues = groupID != &#39;&#39; &amp;&amp; recveiver != &#39;&#39;;

    final messageMap = messageIDMap[id];
    final messageInfo = messageMap[&quot;messageInfo&quot;];
    final type = messageMap[&quot;messageInfo&quot;][&quot;type&quot;];
    if (haveTwoValues) {
      return CommonUtils.returnErrorForValueCb&lt;V2TimMessage&gt;({&#39;code&#39;: 6017, &#39;desc&#39;: &quot;receiver and groupID cannot set at the same time&quot;, &#39;data&#39;: V2TimMessage(elemType: 1).toJson()});
    }
    if (id == null || messageMap == null) {
      return CommonUtils.returnErrorForValueCb&lt;V2TimMessage&gt;({&#39;code&#39;: 6017, &#39;desc&#39;: &quot;id cannot be empty or message cannot find&quot;, &#39;data&#39;: V2TimMessage(elemType: 1).toJson()});
    }
    final convType = groupID != &#39;&#39; ? &#39;GROUP&#39; : &#39;C2C&#39;;
    final sendToUserID = convType == &#39;GROUP&#39; ? groupID : recveiver;
    final needReadReceipt = params[&#39;needReadReceipt&#39;];
    final cloudCustomData = params[&#39;cloudCustomData&#39;] ?? &quot;&quot;;
    switch (type) {
      case &quot;text&quot;:
        {
          String text = messageInfo[&quot;textElem&quot;][&quot;text&quot;];
          final createElemParams = CreateMessage.createTextMessage(userID: sendToUserID, text: text, cloudCustomData: cloudCustomData, convType: convType, needReadReceipt: needReadReceipt, priority: params[&#39;priority&#39;]);
          messageElem = timeweb!.createTextMessage(createElemParams);
          break;
        }
      case &quot;custom&quot;:
        {
          final customMessage = CreateMessage.createCustomMessage(
              userID: sendToUserID,
              customData: messageInfo[&quot;customElem&quot;][&quot;data&quot;],
              convType: convType,
              cloudCustomData: cloudCustomData,
              needReadReceipt: needReadReceipt,
              extension: messageInfo[&#39;customElem&#39;][&#39;extension&#39;],
              description: messageInfo[&#39;customElem&#39;][&#39;desc&#39;],
              priority: params[&#39;priority&#39;]);
          messageElem = timeweb!.createCustomMessage(customMessage);
          break;
        }
      case &quot;face&quot;:
        {
          final faceMessage = CreateMessage.createFaceMessage(
              userID: sendToUserID, data: messageInfo[&quot;faceElem&quot;][&quot;data&quot;], index: messageInfo[&quot;faceElem&quot;][&quot;index&quot;], cloudCustomData: cloudCustomData, needReadReceipt: needReadReceipt, convType: convType, priority: params[&#39;priority&#39;]);
          messageElem = timeweb!.createFaceMessage(faceMessage);
          break;
        }
      case &quot;image&quot;:
        {
          final progressCallback = allowInterop((double progress) async {
            final messageInstance = await V2TIMMessage.convertMessageFromWebToDart(messageElem);
            if (messageListener.isNotEmpty) {
              messageInstance[&#39;id&#39;] = id;
              for (var listener in messageListener.values) {
                listener.onSendMessageProgress(V2TimMessage.fromJson(messageInstance), progress.toInt());
              }
            }
          });
          final createElemParams = CreateMessage.createImageMessage(
              userID: sendToUserID, file: messageInfo[&quot;imageElem&quot;][&quot;file&quot;], convType: convType, cloudCustomData: cloudCustomData, needReadReceipt: needReadReceipt, progressCallback: progressCallback, priority: params[&#39;priority&#39;]);
          messageElem = timeweb!.createImageMessage(createElemParams);
          break;
        }
      case &quot;textAt&quot;:
        {
          final createElemParams = CreateMessage.createTextAtMessage(
              groupID: sendToUserID, text: messageInfo[&quot;textElem&quot;][&#39;text&#39;], priority: params[&#39;priority&#39;], needReadReceipt: needReadReceipt, cloudCustomData: cloudCustomData, atList: messageInfo[&quot;textElem&quot;][&#39;atUserList&#39;]);
          messageElem = timeweb!.createTextAtMessage(createElemParams);
          break;
        }
      case &quot;location&quot;:
        {
          final createElemParams = CreateMessage.createLocationMessage(
              description: messageInfo[&quot;locationElem&quot;][&#39;description&#39;],
              longitude: messageInfo[&quot;locationElem&quot;][&#39;longitude&#39;],
              latitude: messageInfo[&quot;locationElem&quot;][&#39;latitude&#39;],
              cloudCustomData: cloudCustomData,
              needReadReceipt: needReadReceipt,
              priority: params[&#39;priority&#39;],
              userID: sendToUserID);
          messageElem = timeweb!.createLocationMessage(createElemParams);
          break;
        }
      case &quot;mergeMessage&quot;:
        {
          List&lt;String&gt; msgList = messageInfo[&quot;mergerElem&quot;][&#39;msgIDList&#39;];
          List&lt;dynamic&gt; messageList = msgList.map((e) =&gt; timeweb!.findMessage(e)).toList();
          String titile = messageInfo[&quot;mergerElem&quot;][&#39;title&#39;];
          List&lt;String&gt; abstractList = messageInfo[&quot;mergerElem&quot;][&#39;abstractList&#39;];
          String compatibleText = messageInfo[&quot;mergerElem&quot;][&#39;compatibleText&#39;];
          final createElemParams = CreateMessage.createMereMessage(
              userID: sendToUserID,
              messageList: messageList,
              title: titile,
              convType: convType,
              cloudCustomData: cloudCustomData,
              priority: params[&#39;priority&#39;],
              abstractList: abstractList,
              needReadReceipt: needReadReceipt,
              compatibleText: compatibleText);
          messageElem = timeweb!.createMergerMessage(createElemParams);
          break;
        }
      case &quot;forwardMessage&quot;:
        {
          final msgID = messageInfo[&#39;msgID&#39;];
          final createElemParams = CreateMessage.createForwardMessage(
            message: timeweb!.findMessage(msgID),
            userID: sendToUserID,
            cloudCustomData: cloudCustomData,
            needReadReceipt: needReadReceipt,
            priority: params[&#39;priority&#39;],
          );

          messageElem = timeweb!.createForwardMessage(createElemParams);
          break;
        }
      case &quot;video&quot;:
        {
          final progressCallback = allowInterop((double progress) async {
            final messageInstance = await V2TIMMessage.convertMessageFromWebToDart(messageElem);
            if (messageListener.isNotEmpty) {
              messageInstance[&#39;id&#39;] = id;
              for (var listener in messageListener.values) {
                listener.onSendMessageProgress(V2TimMessage.fromJson(messageInstance), progress.toInt());
              }
            }
          });
          final createElemParams = CreateMessage.createVideoMessage(
              userID: sendToUserID, file: messageInfo[&#39;videoElem&#39;][&#39;file&#39;], convType: convType, cloudCustomData: cloudCustomData, needReadReceipt: needReadReceipt, progressCallback: progressCallback, priority: params[&#39;priority&#39;]);
          messageElem = timeweb!.createVideoMessage(createElemParams);
          break;
        }
      case &quot;file&quot;:
        {
          final progressCallback = allowInterop((double progress) async {
            final messageInstance = await V2TIMMessage.convertMessageFromWebToDart(messageElem);
            if (messageListener.isNotEmpty) {
              messageInstance[&#39;id&#39;] = id;
              for (var listener in messageListener.values) {
                listener.onSendMessageProgress(V2TimMessage.fromJson(messageInstance), progress.toInt());
              }
            }
          });
          final createElemParams = CreateMessage.createFileMessage(
              userID: sendToUserID, file: messageInfo[&#39;fileElem&#39;][&#39;file&#39;], convType: convType, cloudCustomData: cloudCustomData, needReadReceipt: needReadReceipt, progressCallback: progressCallback, priority: params[&#39;priority&#39;]);
          messageElem = timeweb!.createFileMessage(createElemParams);
          break;
        }
    }
    final res = await wrappedPromiseToFuture(timeweb!.sendMessage(
        messageElem,
        mapToJSObj({
          &quot;onlineUserOnly&quot;: params[&#39;onlineUserOnly&#39;],
          &quot;messageControlInfo&quot;: mapToJSObj({&quot;excludedFromUnreadCount&quot;: params[&quot;isExcludedFromUnreadCount&quot;], &quot;excludedFromLastMessage&quot;: params[&quot;isExcludedFromLastMessage&quot;]})
        })));
    final code = res.code;
    if (code == 0) {
      final message = jsToMap(res.data)[&#39;message&#39;];
      final formatedMessage = await V2TIMMessage.convertMessageFromWebToDart(message);
      messageIDMap.remove(id);
      return CommonUtils.returnSuccess&lt;V2TimMessage&gt;(formatedMessage);
    } else {
      return CommonUtils.returnErrorForValueCb&lt;V2TimMessage&gt;(&#39;发送消息失败&#39;);
    }
  } catch (error) {
    messageIDMap.remove(id);
    final mapMessageElem = jsToMap(messageElem);
    mapMessageElem[&#39;status&#39;] = &quot;fail&quot;;
    final formatedMessage = await V2TIMMessage.convertMessageFromWebToDart(messageElem);
    return CommonUtils.returnErrorForValueCb&lt;V2TimMessage&gt;(error, resultData: formatedMessage);
  }
}</code></pre>
</section>


  </div> <!-- /.main-content -->

  <div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
    <!-- The search input and breadcrumbs below are only responsively visible at low resolutions. -->
<header id="header-search-sidebar" class="hidden-l">
  <form class="search-sidebar" role="search">
    <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
    <li><a href="../../index.html">tencent_cloud_chat_sdk</a></li>
    <li><a href="../../web_manager_v2_tim_message_manager/web_manager_v2_tim_message_manager-library.html">v2_tim_message_manager</a></li>
    <li><a href="../../web_manager_v2_tim_message_manager/V2TIMMessageManager-class.html">V2TIMMessageManager</a></li>
    <li class="self-crumb">sendMessageForNew&lt;<wbr><span class="type-parameter">T</span>, <span class="type-parameter">F</span>&gt; method</li>
</ol>


    <h5>V2TIMMessageManager class</h5>
    <div id="dartdoc-sidebar-left-content"></div>
  </div><!--/.sidebar-offcanvas-->

  <div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
</div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    tencent_cloud_chat_sdk
      8.5.6864-beta.7
  </span>

  
</footer>



<script src="../../static-assets/highlight.pack.js?v1"></script>
<script src="../../static-assets/docs.dart.js"></script>



</body>

</html>

